home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / arp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  5.4 KB  |  143 lines

  1. /* @(#) $Header: arp.h,v 1.4 90/10/12 19:25:07 deyke Exp $ */
  2.  
  3. #ifndef _ARP_H
  4. #define _ARP_H
  5.  
  6. #ifndef _GLOBAL_H
  7. #include "global.h"
  8. #endif
  9.  
  10. #ifndef _MBUF_H
  11. #include "mbuf.h"
  12. #endif
  13.  
  14. #ifndef _IFACE_H
  15. #include "iface.h"
  16. #endif
  17.  
  18. #ifndef _TIMER_H
  19. #include "timer.h"
  20. #endif
  21.  
  22. /* Lifetime of a valid ARP entry */
  23. #define ARPLIFE        900        /* 15 minutes */
  24. /* Lifetime of a pending ARP entry */
  25. #define PENDTIME    45      /* 45 seconds */
  26.  
  27. /* ARP definitions (see RFC 826) */
  28.  
  29. #define ARPLEN      16      /* Size of ARP hdr, minus hardware addresses */
  30.  
  31. /* Address size definitions */
  32. #define IPALEN      4       /* Length in bytes of an IP address */
  33. #define MAXHWALEN   255        /* Maximum length of a hardware address */
  34.  
  35. /* ARP opcodes */
  36. #define ARP_REQUEST     1
  37. #define ARP_REPLY       2
  38. #define RARP_REQUEST    3
  39. #define RARP_REPLY        4
  40.  
  41. /* Hardware types */
  42. #define ARP_NETROM      0       /* Fake for NET/ROM (never actually sent) */
  43. #define ARP_ETHER       1       /* Assigned to 10 megabit Ethernet */
  44. #define ARP_EETHER      2       /* Assigned to experimental Ethernet */
  45. #define ARP_AX25        3       /* Assigned to AX.25 Level 2 */
  46. #define ARP_PRONET      4       /* Assigned to PROnet token ring */
  47. #define ARP_CHAOS       5       /* Assigned to Chaosnet */
  48. #define ARP_IEEE802     6       /* Who uses this? */
  49. #define ARP_ARCNET      7
  50. #define ARP_APPLETALK   8
  51. extern char *Arptypes[];        /* Type fields in ASCII, defined in arpcmd */
  52. #define NHWTYPES 9
  53.  
  54. /* Table of hardware types known to ARP */
  55. struct arp_type {
  56.     int16 hwalen;           /* Hardware length */
  57.     int16 iptype;           /* Hardware type field for IP */
  58.     int16 arptype;          /* Hardware type field for ARP */
  59.     int16 pendtime;         /* # secs to wait pending response */
  60.     char *bdcst;            /* Hardware broadcast address */
  61.     char *(*format) __ARGS((char *,char *));
  62.                                 /* Function that formats addresses */
  63.     int (*scan) __ARGS((char *,char *));
  64.                                 /* Reverse of format */
  65. };
  66. extern struct arp_type Arp_type[];
  67. #define NULLATYPE       (struct arp_type *)0
  68.  
  69. /* Format of an ARP request or reply packet. From p. 3 */
  70. struct arp {
  71.         int16 hardware;                 /* Hardware type */
  72.         int16 protocol;                 /* Protocol type */
  73.         char hwalen;                    /* Hardware address length, bytes */
  74.         char pralen;                    /* Length of protocol address */
  75.         int16 opcode;                   /* ARP opcode (request/reply) */
  76.         char shwaddr[MAXHWALEN];        /* Sender hardware address field */
  77.         int32 sprotaddr;                /* Sender Protocol address field */
  78.         char thwaddr[MAXHWALEN];        /* Target hardware address field */
  79.         int32 tprotaddr;                /* Target protocol address field */
  80. };
  81.  
  82. /* Format of ARP table */
  83. struct arp_tab {
  84.         struct arp_tab *next;   /* Doubly-linked list pointers */
  85.         struct arp_tab *prev;
  86.         struct timer timer;     /* Time until aging this entry */
  87.         struct mbuf *pending;   /* Queue of datagrams awaiting resolution */
  88.         int32 ip_addr;          /* IP Address, host order */
  89.         int16 hardware;         /* Hardware type */
  90.         int flags;                /* type of ax25 connection */
  91. #define    DATAGRAM_MODE    0        /* Send datagrams in raw link frames */
  92. #define    CONNECT_MODE    1        /* Send datagrams in connected mode */
  93. #define IPCAM_MODE        2       /* Send datagrams in IPCAM mode */
  94.         char state;             /* (In)complete */
  95. #define ARP_PENDING     0
  96. #define ARP_VALID       1
  97.         char pub;               /* Respond to requests for this entry? */
  98.         char *hw_addr;          /* Hardware address */
  99.         int16 hwalen;            /* hardware length used for saving */
  100. };
  101. #define NULLARP (struct arp_tab *)0
  102. extern struct arp_tab *Arp_tab[];
  103.  
  104. struct arp_stat {
  105.         unsigned recv;          /* Total number of ARP packets received */
  106.         unsigned badtype;       /* Incoming requests for unsupported hardware */
  107.         unsigned badlen;        /* Incoming length field(s) didn't match types */
  108.         unsigned badaddr;       /* Bogus incoming addresses */
  109.         unsigned inreq;         /* Incoming requests for us */
  110.         unsigned replies;       /* Replies sent */
  111.         unsigned outreq;        /* Outoging requests sent */
  112. };
  113. extern struct arp_stat Arp_stat;
  114.  
  115. struct arp_saverecord {
  116.   int32 ip_addr;          /* IP address, host order */
  117.   int16 hardware;         /* Hardware type */
  118.   int    flags;              /* AX.25 connection type */
  119.   int16 hwalen;           /* Length of hardware address */
  120.   char  pub;              /* Publish this entry? */
  121. };
  122.  
  123. #define ARP_FILE_VERSION   3             /* incl. ax25 conn. mode */
  124. #define ARP_SAVETIME       (60*10)
  125.  
  126. /* In arp.c: */
  127. struct arp_tab *arp_add __ARGS((int32 ipaddr,int16 hardware,char *hw_addr,
  128.         int pub,int flags));
  129. void arp_drop __ARGS((void *p));
  130. int arp_init __ARGS((unsigned int hwtype,int hwalen,int iptype,int arptype,
  131.         int pendtime,char *bdcst,char *(*format) __ARGS((char *,char *)),
  132.         int  (*scan) __ARGS((char *,char *)) ));
  133. void arp_input __ARGS((struct iface *iface,struct mbuf *bp));
  134. struct arp_tab *arp_lookup __ARGS((int16 hardware,int32 ipaddr));
  135. char *res_arp __ARGS((struct iface *iface,int16 hardware,int32 target,struct mbuf *bp));
  136.  
  137. /* In arphdr.c: */
  138. struct mbuf *htonarp __ARGS((struct arp *arp));
  139. int ntoharp __ARGS((struct arp *arp,struct mbuf **bpp));
  140.  
  141. #endif /* _ARP_H */
  142.  
  143.